package com.concerneyes.trytoglasses;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

import com.concerneyes.R;

/**
 * Created by Administrator on 2017/6/19 0019.
 */

public class FragmentPagerAdapter extends BaseAdapter {
    Context mContext;
    private int selectItem;
    private int drawable1[] = new int[]{R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d, R.drawable.e};

    public FragmentPagerAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;          //这里的目的是可以让图片循环浏览
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setSelectItem(int selectItem) {

        if (this.selectItem != selectItem) {
            this.selectItem = selectItem;
            notifyDataSetChanged();
        }
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(mContext);
        imageView.setImageResource(drawable1[position % drawable1.length]);
//取余，让图片循环浏览

        if (selectItem == position) {
            Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.my_scale_action);    //实现动画效果
            imageView.setLayoutParams(new Gallery.LayoutParams(1005, 1200));
            imageView.startAnimation(animation);  //选中时，这是设置的比较大
        } else {
            imageView.setLayoutParams(new Gallery.LayoutParams(750, 900));
//未选中
        }
        return imageView;
    }

}
